<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
		<title>电子商城</title>
		<link href="styles/style.css" rel="stylesheet" type="text/css" />

		<script type="text/javascript">
			function validate(input) {
				var number = input.value;
				if (number.length == 0) {
					input.value = "0";
					return;
				} else if (number.length > 1 && number.indexOf("0") == 0) {
					input.value = number.substring(1, number.length);
					return;
				}
				var patrn = /^\d+$/;
				if (!patrn.exec(input.value)) {
					alert("请输入正整数");
					input.value = number.substring(0, number.length - 1);
					return;
				}
			}

			function setSummary(index, price) {
				try {
					var number = 0;
					number = document.getElementById('count' + index).value;
					var fPrice = parseFloat(price) * parseInt(number);
					document.getElementById('summary' + index).innerHTML = fPrice;
					setAllMoney();
				} catch (err) {}
			}

			function setAllMoney() {
				try {
					var num = document.getElementsByName('num').length;
					var sum = 0.0;
					for (var i = 1; i < num + 1; i++) {
						var fPrice = document.getElementById('summary' + i).innerHTML;
						sum = (sum * 100 + fPrice * 100) / 100;
					}
					document.getElementById('label_money').innerHTML = sum;
				} catch (err) {}
			}

			window.onload = function() {
				try {
					setAllMoney();
				} catch (err) {}
			}
		</script>

	</head>

	<body>
	<%
		int flag = 0;
		if(request.getSession().getAttribute("flag") != null)
			flag = (int)request.getSession().getAttribute("flag");
		if (flag == 38)
			out.print("<script>alert('商品添加到购物车成功!')</script>");
		else if (flag == 40)
			out.print("<script>alert('购物车信息删除成功!')</script>");
		else if (flag == 41)
			out.print("<script>alert('购物车信息删除失败!')</script>");
		else if (flag == 42)
			out.print("<script>alert('结账成功，订单创建成功!')</script>");
		request.getSession().setAttribute("flag", 0);
	%>
		<header>

			<div class="nav-bg">
				<div class="container">

					<ul class="nav-top">

						<li><a href="gouwuche.jsp"><i class="iconfont" >&#xe623;</i>购物车0件</a></li>

						<li id="gundong" >您  的 满 意 是 我 们 最 大 的 幸 福， 祝 你 购 物 愉 快!</li>


						<li style="float: left;">有 问 题 请 您 及 时 拨 打 24 小 时 服 务 热 线 4 0 0 8 0 0 6 0 0</li>
					</ul>
					<b>  <a > 会员等级
						<c:if test="${user.level eq 1}"><img src="images/tongpai.png"/></c:if>
						<c:if test="${user.level eq 2}"><img src="images/yinpaihuiyuan.png"/></c:if>
						<c:if test="${user.level eq 3}"><img src="images/jinpaihuiyuan.png"/></c:if>
					</a></b>
				</div>
			</div>
			<div class="container">

				<marquee width="500px" style="float: left;">
					<p style="font-size:30px;color:orange; margin-top: 22px;">欢迎您!${user.name}</p>
				</marquee>

			</div>

		</header>

		<div class="nav">
			<div class="container">
				<a href="<c:url value="/GoodsShow"/>" >首页</a> |
				<a href="<c:url value="/UserUpdate"/>">会员资料修改</a> |
				<a href="<c:url value="/GouWuCheList"/>">购物车</a> |
				<a href="<c:url value="/OrderList"/>">查看订单</a> |
				<a href="manage1.jsp">后台管理</a> |
				<a href="denglu.jsp">会员登录</a>


			</div>
		</div>


		<div id="container">
		   <div id="content">
				<div class="cartDet">
					<div class="bg">
						<h4>
							购物车
						</h4>
							<table width="100%" border="0" cellspacing="0" cellpadding="0">
								<tr>
									<th scope="col" width="15%">
										编号
									</th>
									<th scope="col" width="30%">
										商品名称
									</th>
									<th scope="col" width="15%">
										单价
									</th>
									<th scope="col" width="15%">
										数量
									</th>
									<th scope="col" width="15%">
										金额
									</th>
									<th scope="col" width="10%">
										删除
									</th>
								</tr>
								<c:forEach items="${TrolleyInfo}" var="Ti" varStatus="status">
								<form action="<c:url value="/GouWuCheList"/>" method="post">
									<tr id="num">
											<input name="id" value="${Ti.id}" style="display: none"/>
										<td>${status.count}</td>
										<td>${Ti.goodsName}</td>
										<td>￥${Ti.unitPrice}</td>
										<td>
											<input id="count1" name="count" size="8" value="${Ti.count}" onblur="setSummary('1','50.0')" class="input" onchange="submit()" />
										</td>
										<input type="hidden" name="hidden" value="1" id="hidden" />
										<td>
											￥${Ti.price}
										</td>
										<td align="center">
											<img src="images/35.gif" onclick="window.location.href='/GouWuCheDelete?trolleyInfoId=${Ti.id}'" style="border:0; float:inherit; cursor:hand" />
										</td>
									</tr>
								</form>
								</c:forEach>

							</table>
							<p class="ali_right">
								合计总金额：￥${sumPrice}
							</p>

							<p class="ali_center">
								<a href="<c:url value="/GoodsShow"/>">继续购物</a> |
								<a href="jiezhang.jsp">收银结账</a>
							</p>


					</div>
				</div>
			</div>
		</div>
	</body>
	<%
		if (request.getSession().getAttribute("levelChange") != null) {
			int flag1 = (int)request.getSession().getAttribute("levelChange");
			if (flag1 == 1)
				out.print("<script>alert('恭喜你升级到铜牌会员!')</script>");
			else if (flag1 == 2)
				out.print("<script>alert('恭喜你升级到银牌会员!')</script>");
			else if (flag1 == 3)
				out.print("<script>alert('恭喜你升级到金牌会员!')</script>");
			request.getSession().setAttribute("levelChange", 0);
		}
	%>
<script type="text/javascript">


function gundong(){
		   var div=document.getElementById("gundong")
	       var txt=div.innerHTML;

	        var arr=txt.split("");//把字符串变成数组

	      console.log(arr)

	       var first=arr.shift(); //删除数组里
	       console.log(first)

	       arr.push(first);
	      console.log(arr)
	          txt=arr.join("")

          div.innerHTML=txt
             console.log(txt);
		}

	setInterval(gundong,500)
	</script>
</html>